/**
 * @file WMIdentify_UI.cpp
 * @author 高宁 (3406402603@qq.com)
 * @brief 因为调试过程中的UI系统与本体过于无关，而且因为架构比较无脑，很占地方，所以将其与本身的WMIdentify.cpp分开
 * @version 0.1
 * @date 2023-02-20
 * 
 * @copyright Copyright (c) 2023
 * 
 */
#include "WMIdentify.hpp"
#include <opencv2/imgproc/types_c.h>

void WMIdentify::windowsManager(GlobalParam &gp, int page, int &row, int tag)
{
    cv::putText(this->img, "Page:" + std::to_string(page)+"  Left:Z  Right:C", cv::Point(20, 400), 2, 0.5, cv::Scalar(255, 255, 0));
    cv::putText(this->img, "Row:" + std::to_string(row)+"  Up:R  Down:F", cv::Point(20, 425), 2, 0.5, cv::Scalar(255, 255, 0));
    if (page == 0)
    {
        if (row == 0)
            cv::putText(this->img, "HMax:" + std::to_string(gp.hmax), cv::Point(20, 20), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "HMax:" + std::to_string(gp.hmax), cv::Point(20, 20), 2, 0.5, cv::Scalar(0, 0, 255));
        if (row == 1)
            cv::putText(this->img, "HMin:" + std::to_string(gp.hmin), cv::Point(20, 45), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "HMin:" + std::to_string(gp.hmin), cv::Point(20, 45), 2, 0.5, cv::Scalar(0, 0, 255));
        if (row == 2)
            cv::putText(this->img, "SMax:" + std::to_string(gp.smax), cv::Point(20, 70), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "SMax:" + std::to_string(gp.smax), cv::Point(20, 70), 2, 0.5, cv::Scalar(0, 0, 255));
        if (row == 3)
            cv::putText(this->img, "SMin:" + std::to_string(gp.smin), cv::Point(20, 95), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "SMin:" + std::to_string(gp.smin), cv::Point(20, 95), 2, 0.5, cv::Scalar(0, 0, 255));
        if (row == 4)
            cv::putText(this->img, "VMax:" + std::to_string(gp.vmax), cv::Point(20, 120), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "VMax:" + std::to_string(gp.vmax), cv::Point(20, 120), 2, 0.5, cv::Scalar(0, 0, 255));
        if (row == 5)
            cv::putText(this->img, "VMin:" + std::to_string(gp.vmin), cv::Point(20, 145), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "VMin:" + std::to_string(gp.vmin), cv::Point(20, 145), 2, 0.5, cv::Scalar(0, 0, 255));
        if (tag == 1)
        {
            if (row == 0)
                gp.hmax += 1;
            if (row == 1)
                gp.hmin += 1;
            if (row == 2)
                gp.smax += 1;
            if (row == 3)
                gp.smin += 1;
            if (row == 4)
                gp.vmax += 1;
            if (row == 5)
                gp.vmin += 1;
        }
        else if (tag == 2)
        {
            if (row == 0)
                gp.hmax += 10;
            if (row == 1)
                gp.hmin += 10;
            if (row == 2)
                gp.smax += 10;
            if (row == 3)
                gp.smin += 10;
            if (row == 4)
                gp.vmax += 10;
            if (row == 5)
                gp.vmin += 10;
        }
        if (tag == 3)
        {
            if (row == 0)
                gp.hmax -= 1;
            if (row == 1)
                gp.hmin -= 1;
            if (row == 2)
                gp.smax -= 1;
            if (row == 3)
                gp.smin -= 1;
            if (row == 4)
                gp.vmax -= 1;
            if (row == 5)
                gp.vmin -= 1;
        }
        else if (tag == 4)
        {
            if (row == 0)
                gp.hmax -= 10;
            if (row == 1)
                gp.hmin -= 10;
            if (row == 2)
                gp.smax -= 10;
            if (row == 3)
                gp.smin -= 10;
            if (row == 4)
                gp.vmax -= 10;
            if (row == 5)
                gp.vmin -= 10;
        }
    }
    if (page == 1)
    {
        if (row == 0)
            cv::putText(this->img, "s_R_min:" + std::to_string(gp.s_R_min), cv::Point(20, 20), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "s_R_min:" + std::to_string(gp.s_R_min), cv::Point(20, 20), 2, 0.5, cv::Scalar(0, 0, 255));
        if (row == 1)
            cv::putText(this->img, "s_R_max:" + std::to_string(gp.s_R_max), cv::Point(20, 45), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "s_R_max:" + std::to_string(gp.s_R_max), cv::Point(20, 45), 2, 0.5, cv::Scalar(0, 0, 255));
        if (row == 2)
            cv::putText(this->img, "R_circularity_min:" + std::to_string(gp.R_circularity_min), cv::Point(20, 70), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "R_circularity_min:" + std::to_string(gp.R_circularity_min), cv::Point(20, 70), 2, 0.5, cv::Scalar(0, 0, 255));
        if (row == 3)
            cv::putText(this->img, "R_circularity_max:" + std::to_string(gp.R_circularity_max), cv::Point(20, 95), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "R_circularity_max:" + std::to_string(gp.R_circularity_max), cv::Point(20, 95), 2, 0.5, cv::Scalar(0, 0, 255));
        if (row == 4)
            cv::putText(this->img, "R_compactness_min:" + std::to_string(gp.R_compactness_min), cv::Point(20, 120), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "R_compactness_min:" + std::to_string(gp.R_compactness_min), cv::Point(20, 120), 2, 0.5, cv::Scalar(0, 0, 255));
        if (row == 5)
            cv::putText(this->img, "R_compactness_max:" + std::to_string(gp.R_compactness_max), cv::Point(20, 145), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "R_compactness_max:" + std::to_string(gp.R_compactness_max), cv::Point(20, 145), 2, 0.5, cv::Scalar(0, 0, 255));
        if (tag == 1)
        {
            if (row == 0)
                gp.s_R_min += 10;
            if (row == 1)
                gp.s_R_max += 10;
            if (row == 2)
                gp.R_circularity_min += 0.01;
            if (row == 3)
                gp.R_circularity_max += 0.01;
            if (row == 4)
                gp.R_compactness_min += 1;
            if (row == 5)
                gp.R_compactness_max += 1;
        }
        else if (tag == 2)
        {
            if (row == 0)
                gp.s_R_min += 100;
            if (row == 1)
                gp.s_R_max += 100;
            if (row == 2)
                gp.R_circularity_min += 0.1;
            if (row == 3)
                gp.R_circularity_max += 0.1;
            if (row == 4)
                gp.R_compactness_min += 10;
            if (row == 5)
                gp.R_compactness_max += 10;
        }
        if (tag == 3)
        {
            if (row == 0)
                gp.s_R_min -= 10;
            if (row == 1)
                gp.s_R_max -= 10;
            if (row == 2)
                gp.R_circularity_min -= 0.01;
            if (row == 3)
                gp.R_circularity_max -= 0.01;
            if (row == 4)
                gp.R_compactness_min -= 1;
            if (row == 5)
                gp.R_compactness_max -= 1;
        }
        else if (tag == 4)
        {
            if (row == 0)
                gp.s_R_min -= 100;
            if (row == 1)
                gp.s_R_max -= 100;
            if (row == 2)
                gp.R_circularity_min -= 0.1;
            if (row == 3)
                gp.R_circularity_max -= 0.1;
            if (row == 4)
                gp.R_compactness_min -= 10;
            if (row == 5)
                gp.R_compactness_max -= 10;
        }
    }
    if (page == 2)
    {
        if (row == 0)
            cv::putText(this->img, "s_wing_min:" + std::to_string(gp.s_wing_min), cv::Point(20, 20), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "s_wing_min:" + std::to_string(gp.s_wing_min), cv::Point(20, 20), 2, 0.5, cv::Scalar(0, 0, 255));
        if (row == 1)
            cv::putText(this->img, "s_wing_max:" + std::to_string(gp.s_wing_max), cv::Point(20, 45), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "s_wing_max:" + std::to_string(gp.s_wing_max), cv::Point(20, 45), 2, 0.5, cv::Scalar(0, 0, 255));
        if (row == 2)
            cv::putText(this->img, "wing_ratio_min:" + std::to_string(gp.wing_ratio_min), cv::Point(20, 70), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "wing_ratio_min:" + std::to_string(gp.wing_ratio_min), cv::Point(20, 70), 2, 0.5, cv::Scalar(0, 0, 255));
        if (row == 3)
            cv::putText(this->img, "wing_ratio_max:" + std::to_string(gp.wing_ratio_max), cv::Point(20, 95), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "wing_ratio_max:" + std::to_string(gp.wing_ratio_max), cv::Point(20, 95), 2, 0.5, cv::Scalar(0, 0, 255));
        if (row == 4)
            cv::putText(this->img, "s_wing_ratio_min:" + std::to_string(gp.s_wing_ratio_min), cv::Point(20, 120), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "s_wing_ratio_min:" + std::to_string(gp.s_wing_ratio_min), cv::Point(20, 120), 2, 0.5, cv::Scalar(0, 0, 255));
        if (row == 5)
            cv::putText(this->img, "s_wing_ratio_max:" + std::to_string(gp.s_wing_ratio_max), cv::Point(20, 145), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "s_wing_ratio_max:" + std::to_string(gp.s_wing_ratio_max), cv::Point(20, 145), 2, 0.5, cv::Scalar(0, 0, 255));
        if (tag == 1)
        {
            if (row == 0)
                gp.s_wing_min += 10;
            if (row == 1)
                gp.s_wing_max += 10;
            if (row == 2)
                gp.wing_ratio_min += 0.01;
            if (row == 3)
                gp.wing_ratio_max += 0.01;
            if (row == 4)
                gp.s_wing_ratio_min += 0.01;
            if (row == 5)
                gp.s_wing_ratio_max += 0.01;
        }
        else if (tag == 2)
        {
            if (row == 0)
                gp.s_wing_min += 100;
            if (row == 1)
                gp.s_wing_max += 100;
            if (row == 2)
                gp.wing_ratio_min += 0.1;
            if (row == 3)
                gp.wing_ratio_max += 0.1;
            if (row == 4)
                gp.s_wing_ratio_min += 0.1;
            if (row == 5)
                gp.s_wing_ratio_max += 0.1;
        }
        if (tag == 3)
        {
            if (row == 0)
                gp.s_wing_min -= 10;
            if (row == 1)
                gp.s_wing_max -= 10;
            if (row == 2)
                gp.wing_ratio_min -= 0.01;
            if (row == 3)
                gp.wing_ratio_max -= 0.01;
            if (row == 4)
                gp.s_wing_ratio_min -= 0.01;
            if (row == 5)
                gp.s_wing_ratio_max -= 0.01;
        }
        else if (tag == 4)
        {
            if (row == 0)
                gp.s_wing_min -= 100;
            if (row == 1)
                gp.s_wing_max -= 100;
            if (row == 2)
                gp.wing_ratio_min -= 0.1;
            if (row == 3)
                gp.wing_ratio_max -= 0.1;
            if (row == 4)
                gp.s_wing_ratio_min -= 0.1;
            if (row == 5)
                gp.s_wing_ratio_max -= 0.1;
        }
    }
    if (page == 3)
    {
        if (row == 0)
            cv::putText(this->img, "s_winghat_min:" + std::to_string(gp.s_winghat_min), cv::Point(20, 20), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "s_winghat_min:" + std::to_string(gp.s_winghat_min), cv::Point(20, 20), 2, 0.5, cv::Scalar(0, 0, 255));
        if (row == 1)
            cv::putText(this->img, "s_winghat_max:" + std::to_string(gp.s_winghat_max), cv::Point(20, 45), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "s_winghat_max:" + std::to_string(gp.s_winghat_max), cv::Point(20, 45), 2, 0.5, cv::Scalar(0, 0, 255));
        if (row == 2)
            cv::putText(this->img, "winghat_ratio_min:" + std::to_string(gp.winghat_ratio_min), cv::Point(20, 70), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "winghat_ratio_min:" + std::to_string(gp.winghat_ratio_min), cv::Point(20, 70), 2, 0.5, cv::Scalar(0, 0, 255));
        if (row == 3)
            cv::putText(this->img, "winghat_ratio_max:" + std::to_string(gp.winghat_ratio_max), cv::Point(20, 95), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "winghat_ratio_max:" + std::to_string(gp.winghat_ratio_max), cv::Point(20, 95), 2, 0.5, cv::Scalar(0, 0, 255));
        if (row == 4)
            cv::putText(this->img, "s_winghat_ratio_min:" + std::to_string(gp.s_winghat_ratio_min), cv::Point(20, 120), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "s_winghat_ratio_min:" + std::to_string(gp.s_winghat_ratio_min), cv::Point(20, 120), 2, 0.5, cv::Scalar(0, 0, 255));
        if (row == 5)
            cv::putText(this->img, "s_winghat_ratio_max:" + std::to_string(gp.s_winghat_ratio_max), cv::Point(20, 145), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "s_winghat_ratio_max:" + std::to_string(gp.s_winghat_ratio_max), cv::Point(20, 145), 2, 0.5, cv::Scalar(0, 0, 255));
        if (tag == 1)
        {
            if (row == 0)
                gp.s_winghat_min += 10;
            if (row == 1)
                gp.s_winghat_max += 10;
            if (row == 2)
                gp.winghat_ratio_min += 0.01;
            if (row == 3)
                gp.winghat_ratio_max += 0.01;
            if (row == 4)
                gp.s_winghat_ratio_min += 0.01;
            if (row == 5)
                gp.s_winghat_ratio_max += 0.01;
        }
        else if (tag == 2)
        {
            if (row == 0)
                gp.s_winghat_min += 100;
            if (row == 1)
                gp.s_winghat_max += 100;
            if (row == 2)
                gp.winghat_ratio_min += 0.1;
            if (row == 3)
                gp.winghat_ratio_max += 0.1;
            if (row == 4)
                gp.s_winghat_ratio_min += 0.1;
            if (row == 5)
                gp.s_winghat_ratio_max += 0.1;
        }
        if (tag == 3)
        {
            if (row == 0)
                gp.s_winghat_min -= 10;
            if (row == 1)
                gp.s_winghat_max -= 10;
            if (row == 2)
                gp.winghat_ratio_min -= 0.01;
            if (row == 3)
                gp.winghat_ratio_max -= 0.01;
            if (row == 4)
                gp.s_winghat_ratio_min -= 0.01;
            if (row == 5)
                gp.s_winghat_ratio_max -= 0.01;
        }
        else if (tag == 4)
        {
            if (row == 0)
                gp.s_winghat_min -= 100;
            if (row == 1)
                gp.s_winghat_max -= 100;
            if (row == 2)
                gp.winghat_ratio_min -= 0.1;
            if (row == 3)
                gp.winghat_ratio_max -= 0.1;
            if (row == 4)
                gp.s_winghat_ratio_min -= 0.1;
            if (row == 5)
                gp.s_winghat_ratio_max -= 0.1;
        }
    }
    if (page == 4)
    {
        if (row == 0)
            cv::putText(this->img, "dialte1:" + std::to_string(gp.dialte1), cv::Point(20, 20), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "dialte1:" + std::to_string(gp.dialte1), cv::Point(20, 20), 2, 0.5, cv::Scalar(0, 0, 255));
        if (row == 1)
            cv::putText(this->img, "dialte2:" + std::to_string(gp.dialte2), cv::Point(20, 45), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "dialte2:" + std::to_string(gp.dialte2), cv::Point(20, 45), 2, 0.5, cv::Scalar(0, 0, 255));
        if (row == 2)
            cv::putText(this->img, "dialte3:" + std::to_string(gp.dialte3), cv::Point(20, 70), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "dialte3:" + std::to_string(gp.dialte3), cv::Point(20, 70), 2, 0.5, cv::Scalar(0, 0, 255));
        if (row == 3)
            cv::putText(this->img, "switch_UI_contours:" + std::to_string(gp.switch_UI_contours), cv::Point(20, 95), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "switch_UI_contours:" + std::to_string(gp.switch_UI_contours), cv::Point(20, 95), 2, 0.5, cv::Scalar(0, 0, 255));
        if (row == 4)
            cv::putText(this->img, "switch_UI_areas:" + std::to_string(gp.switch_UI_areas), cv::Point(20, 120), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "switch_UI_areas:" + std::to_string(gp.switch_UI_areas), cv::Point(20, 120), 2, 0.5, cv::Scalar(0, 0, 255));
        if (row == 5)
            cv::putText(this->img, "switch_UI:" + std::to_string(gp.switch_UI), cv::Point(20, 145), 2, 0.5, cv::Scalar(255, 0, 0));
        else
            cv::putText(this->img, "switch_UI:" + std::to_string(gp.switch_UI), cv::Point(20, 145), 2, 0.5, cv::Scalar(0, 0, 255));
        if (tag == 1)
        {
            if (row == 0)
                gp.dialte1 += 1;
            if (row == 1)
                gp.dialte2 += 1;
            if (row == 2)
                gp.dialte3 += 1;
            if (row == 3)
                gp.switch_UI_contours = 1 - gp.switch_UI_contours;
            if (row == 4)
                gp.switch_UI_areas = 1 - gp.switch_UI_areas;
            if (row == 5)
                gp.switch_UI = 1 - gp.switch_UI;
        }
        if (tag == 3)
        {
            if (row == 0 && gp.dialte1 > 1)
                gp.dialte1 -= 1;
            if (row == 1 && gp.dialte2 > 1)
                gp.dialte2 -= 1;
            if (row == 2 && gp.dialte3 > 1)
                gp.dialte3 -= 1;
            if (row == 3)
                gp.switch_UI_contours = 1 - gp.switch_UI_contours;
            if (row == 4)
                gp.switch_UI_areas = 1 - gp.switch_UI_areas;
            if (row == 5)
                gp.switch_UI = 1 - gp.switch_UI;
        }
    }
}